/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:23:00 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class BaikiemtratuluanDAL : SqlProvider<BaikiemtratuluanEntity>
    {
        static BaikiemtratuluanDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                BaikiemtratuluanEntity entity = new BaikiemtratuluanEntity();
				entity.FK_iThongtinbaikiemtraID = Int64.Parse("0"+dr["FK_iThongtinbaikiemtraID"].ToString());
				entity.FK_iCauhoiID = Int64.Parse("0"+dr["FK_iCauhoiID"].ToString());
				entity.sNoidung = dr["sNoidung"].ToString();
				entity.fDiem = float.Parse("0"+dr["fDiem"].ToString());
				entity.sNhanxet = dr["sNhanxet"].ToString();
                return entity;
            };
        }
        public static BaikiemtratuluanEntity GetOne(Int64 FK_iThongtinbaikiemtraID, Int64 FK_iCauhoiID )
        {
            string cmdName = "spBaikiemtratuluan_GetByPK";
            SqlParameter[] p = new SqlParameter[2];
               p[0] = new SqlParameter("@FK_iThongtinbaikiemtraID", FK_iThongtinbaikiemtraID);
               p[1] = new SqlParameter("@FK_iCauhoiID", FK_iCauhoiID);
            BaikiemtratuluanEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<BaikiemtratuluanEntity> GetAll()
        {
            string cmdName = "spBaikiemtratuluan_Get";
            return GetList(cmdName);
        }
        
        public static int Add(BaikiemtratuluanEntity entity)
        {
            string cmdName = "spBaikiemtratuluan_Insert";
            return Run(cmdName,false,initParams(entity));

        }
        public static bool Edit(BaikiemtratuluanEntity entity)
        {
            string cmdName = "spBaikiemtratuluan_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 FK_iThongtinbaikiemtraID)
        {
            string cmdName = "spBaikiemtratuluan_Delete";
            SqlParameter p = new SqlParameter("@FK_iThongtinbaikiemtraID", FK_iThongtinbaikiemtraID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(BaikiemtratuluanEntity entity)
        {
            SqlParameter[] p = new SqlParameter[5];
			p[0] = new SqlParameter("@FK_iThongtinbaikiemtraID", entity.FK_iThongtinbaikiemtraID);
			p[1] = new SqlParameter("@FK_iCauhoiID", entity.FK_iCauhoiID);
			p[2] = new SqlParameter("@sNoidung", entity.sNoidung);
			p[3] = new SqlParameter("@fDiem", entity.fDiem);
			p[4] = new SqlParameter("@sNhanxet", entity.sNhanxet);
            return p;
        }
        #endregion
       
    }
}